home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / BARNET / COMPILER / SATHER / !Sather / Library / Base / sa / aref < prev    next >
Text File  |  1996-08-01  |  6KB  |  152 lines

  1. ---------------------------> Sather 1.1 source file <--------------------------
  2. -- Copyright (C) International Computer Science Institute, 1994.  COPYRIGHT  --
  3. -- NOTICE: This code is provided "AS IS" WITHOUT ANY WARRANTY and is subject --
  4. -- to the terms of the SATHER LIBRARY GENERAL PUBLIC LICENSE contained in    --
  5. -- the file "Doc/License" of the Sather distribution.  The license is also   --
  6. -- available from ICSI, 1947 Center St., Suite 600, Berkeley CA 94704, USA.  --
  7. --------> Please email comments to "sather-bugs@icsi.berkeley.edu". <----------
  8.  
  9. -- aref.sa: Built-in reference arrays, primarily to be included.
  10.  
  11. -------------------------------------------------------------------
  12. class AREF{T} is
  13.    -- Built-in arrays of elements of type T. Primarily intended to be
  14.    -- included in reference classes that need an array portion in their
  15.    -- objects. Array indices start at 0 and go up to "asize-1".
  16.    -- All feature names begin with "a" to minimize name conflicts when
  17.    -- include. None of the features work with void(self).  This class is
  18.    -- primarily meant to be included. ARRAY{T} provides an array 
  19.    -- abstraction that is meant to be used directly.
  20.    
  21.    asize:INT pre ~void(self) is builtin AREF_ASIZE; end;
  22.       -- The number of elements in self. Classes which inherit this may
  23.       -- replace this by a constant to get constant sized objects (and 
  24.       -- the compiler may optimize certain operations in this case).
  25.       -- Built-in.
  26.  
  27.    create(n:INT):SAME 
  28.       -- A new array with `n' elements.
  29.       pre n>=0 is
  30.       return new(n) end;
  31.    
  32.    aget(ind:INT):T
  33.       -- The element of self with index `ind'. Built-in.
  34.       pre ~void(self) and ind.is_bet(0,asize-1) is
  35.          builtin AREF_AGET; 
  36.       end;
  37.  
  38.    aset(ind:INT, val:T)
  39.       -- Set the element of self with index `ind' to `val'. Built-in. 
  40.       pre ~void(self) and ind.is_bet(0,asize-1) is 
  41.          builtin AREF_ASET;
  42.       end;
  43.  
  44.    aclear 
  45.       -- Set each element of self to nil. Built-in.
  46.       pre ~void(self) is 
  47.          builtin AREF_ACLEAR; 
  48.       end;
  49.  
  50.    aelt!:T 
  51.       -- Yield each element of self in order. Built-in.
  52.     pre ~void(self) is 
  53.        builtin AREF_AELTB;
  54.     end;
  55.  
  56.    aelt!(once beg:INT):T
  57.       -- Yield each element of self starting at `beg'. Built-in.
  58.       pre ~void(self) and beg.is_bet(0,asize-1) is
  59.          builtin AREF_AELT_BEGB;
  60.       end;
  61.    
  62.    aelt!(once beg,once num:INT):T
  63.       -- Yield `num' successive elements of self starting at
  64.       -- index `beg'. Built-in.
  65.       pre ~void(self) and beg.is_bet(0,asize-1) and 
  66.           num.is_bet(0,asize-beg) is
  67.          builtin AREF_AELT_BEG_NUMB;
  68.       end;
  69.  
  70.    private is_legal_aelts_arg( beg, num, step:INT) :BOOL is
  71.       -- True if the arguments are legal values for `aelts'.
  72.       return beg.is_bet(0,asize-1) and
  73.          ((step>0 and num.is_bet(0,(asize-beg+step-1)/step)) or
  74.           (step<0 and num.is_bet(0,(beg-step)/-step))) end;
  75.    
  76.    aelt!(once beg,once num,once step:INT):T
  77.       -- Yield `num' elements of self starting at `beg' and stepping
  78.       -- by `step' which must not be zero. Built-in.
  79.       pre ~void(self) and is_legal_aelts_arg(beg,num,step) is
  80.          builtin AREF_AELT_BEG_NUM_STEPB;
  81.       end;
  82.    
  83.    aset!(val:T) 
  84.       -- Set successive elements of self to the values `val'. 
  85.       -- Built-in.
  86.       pre ~void(self) is 
  87.          builtin AREF_ASETB;
  88.       end;
  89.  
  90.    aset!(once beg:INT,val:T)
  91.       -- Set successive elements of self starting at `beg' to the 
  92.       -- values `val'. 
  93.       pre ~void(self) and beg.is_bet(0,asize-1) is
  94.          builtin AREF_ASET_BEGB;
  95.       end;
  96.    
  97.    aset!(once beg,once num:INT,val:T)
  98.       -- Set `num' successive elements of self starting at `beg'
  99.       -- to the values `val'. 
  100.       pre ~void(self) and  beg.is_bet(0,asize-1) and 
  101.           num.is_bet(0,asize-beg) is
  102.          builtin AREF_ASET_BEG_NUMB;
  103.       end;
  104.  
  105.    aset!(once beg,once num,once step:INT, val:T)
  106.       -- Set `num' elements of self starting at `beg' stepping 
  107.       -- by `step' to the values `val'. `step' must not be zero. 
  108.       pre ~void(self) and is_legal_aelts_arg(beg,num,step) is
  109.          builtin AREF_ASET_BEG_NUM_STEPB;
  110.       end;
  111.    
  112.    acopy(src:SAME)
  113.       -- Copy as many elements from `src' to self as will fit.
  114.       -- Built-in.
  115.       pre ~void(self) and ~void(src) is
  116.          builtin AREF_ACOPY;
  117.       end;
  118.    
  119.    acopy(beg:INT, src:SAME)
  120.       -- Copy as many elements from `src' to self as will fit when
  121.       -- starting at index `beg' of self. 
  122.       pre ~void(self) and ~void(src) and (beg.is_bet(0,asize-1) or src.asize=0) is
  123.           builtin AREF_ACOPY_BEG;
  124.       end;
  125.    
  126.    acopy(beg,num:INT, src:SAME)
  127.       -- Copy `num' elements from `src' to self starting at index
  128.       -- `beg' of self.
  129.       pre ~void(self) and ~void(src) and beg.is_bet(0,asize-1) and 
  130.           num.is_bet(0,asize-beg) and num<=src.asize is
  131.          builtin AREF_ACOPY_BEG_NUM;
  132.       end;
  133.    
  134.    acopy(beg,num,srcbeg:INT, src:SAME)
  135.       -- Copy `num' elements from `src' to self starting at index
  136.       -- `beg' of self and index `srcbeg' of `src'. Built-in.
  137.       pre ~void(self) and ~void(src) and beg.is_bet(0,asize-1) and 
  138.           num.is_bet(0,asize-beg) and num<=src.asize-srcbeg is   
  139.          builtin AREF_ACOPY_BEG_NUM_SRCBEG;
  140.       end;
  141.    
  142.    aind!:INT
  143.       -- Yield the indices of self in order.
  144.       pre ~void(self) is builtin AREF_AINDB; end;
  145.  
  146.    array_ptr:C_PTR is
  147.       builtin AREF_ARRAY_PTR;
  148.    end;
  149. end; -- class AREF{T}
  150.  
  151. -------------------------------------------------------------------
  152.